package com.zhs;

import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestProducer {
    public static void main(String[]args) throws Exception{
        ApplicationContext context=new ClassPathXmlApplicationContext("spring-producer.xml");
        SpringProducer producer = (SpringProducer)context.getBean("producer");
        for(int i=0;i<20;i++){
            Message message=new Message(
                    "topic_java", //主题
                    "tagA", //标签
                    ("hello java spring demo rocketmq "+i).getBytes(RemotingHelper.DEFAULT_CHARSET)  //发送消息内容
            );
            //发送消息返回结果
            SendResult result=producer.getDefaultMQProducer().send(message);
            System.out.printf("%s%n",result);
        }
    }
}
